package com.muqi.app.pj.shops;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.muqi.app.network.http.GlideImageUtils;
import com.muqi.app.qlearn.student.R;

public class FictitiousAdapter extends BaseAdapter {
	private List<FictitiousShopInfo> infos;
	private Context content;
	private LayoutInflater inflater;

	public FictitiousAdapter(List<FictitiousShopInfo> infos, Context content) {
		super();
		this.infos = infos;
		this.content = content;
		inflater = LayoutInflater.from(content);
	}

	@Override
	public int getCount() {
		return infos.size();
	}

	@Override
	public FictitiousShopInfo getItem(int arg0) {
		return infos.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(final int arg0, View arg1, ViewGroup arg2) {
		TreeViewHolder holder = null;
		final FictitiousShopInfo itemInfo = infos.get(arg0);
		if (arg1 == null) {
			arg1 = inflater.inflate(R.layout.item_fictitious, null);
			holder = new TreeViewHolder();
			holder.itemBg=(RelativeLayout) arg1.findViewById(R.id.ll_shop);
			holder.itemIv = (ImageView) arg1.findViewById(R.id.iv_shop_icon);
		
			holder.itemName = (TextView) arg1.findViewById(R.id.tv_shop_name);
			holder.itemPrice = (TextView) arg1.findViewById(R.id.tv_shop_money);
			arg1.setTag(holder);
		} else {
			holder = (TreeViewHolder) arg1.getTag();
		}
		if(infos.size()==2 && arg0==1){
			GlideImageUtils.setImageLoader(content, itemInfo.prizeInfo.fileurl.fileurl_02,
					holder.itemIv, R.drawable.shop_tennis);
			holder.itemBg.setBackgroundResource(R.drawable.corners_shop_green);
		}else{
			holder.itemBg.setBackgroundResource(R.drawable.corners_shop_yellow);
			GlideImageUtils.setImageLoader(content, itemInfo.prizeInfo.fileurl.fileurl_02,
					holder.itemIv, R.drawable.shop_broom);
		}
		
		holder.itemName.setText(itemInfo.prizeInfo.title);
		holder.itemPrice.setText(itemInfo.credits);
		return arg1;
	}

	private class TreeViewHolder {
		RelativeLayout itemBg;
		TextView itemName;
		TextView itemPrice;
		ImageView itemIv;
	}
}
